<template>
    <section class="chart-container">
        <el-row>
			<el-col :span="24">
			    <div class="front-total-stat">
					总发放量：<i class="front-total-stat-num">{{publishTotal}}</i>&nbsp;&nbsp;
					总使用量：<i class="front-total-stat-num">{{usedTotal}}</i>&nbsp;&nbsp;
					使用率：<i class="front-total-stat-num">{{usedRatio()}}</i>&nbsp;&nbsp;
					总预算：<i class="front-total-stat-num">{{budgetTotal}}</i>&nbsp;&nbsp;
				</div>
			</el-col>
            <el-col :span="24">
                <div id="totalChangingCurveLine" style="width:100%; height:400px;"></div>
            </el-col>
			<el-col :span="24">
			    <div id="couponTypeChartBar" style="width:100%; height:400px;"></div>
			</el-col>
            <el-col :span="12">
                <div id="publishCouponTypePie" style="width:100%; height:400px;"></div>
            </el-col>
			<el-col :span="12">
			    <div id="usedCouponTypePie" style="width:100%; height:400px;"></div>
			</el-col>
        </el-row>
    </section>
</template>

<script>
    import echarts from 'echarts'

    export default {
        data() {
            return {
				publishTotal: 100,
				usedTotal:50,
				budgetTotal:'200元',
                chartColumn: null,
                totalChangingCurveLine: null,
                couponTypeChartBar: null,
                publishCouponTypePie: null,
				usedCouponTypePie: null
            }
        },
		computed:{
			usedRatio(){
				return function (){
					return this.usedTotal / this.publishTotal;
				}
			}
		},
		mounted: function () {
		    this.drawCharts()
		},
        methods: {
			drawCharts() {
			    this.drawLineChart();
				this.drawBarChart();
			    this.drawPieChart();
			},
            drawLineChart() {
                this.totalChangingCurveLine = echarts.init(document.getElementById('totalChangingCurveLine'));
                this.totalChangingCurveLine.setOption({
                    title: {
                        text: 'Line Chart'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['邮件营销', '联盟广告', '搜索引擎']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '邮件营销',
                            type: 'line',
                            stack: '总量',
                            data: [120, 132, 101, 134, 90, 230, 210]
                        },
                        {
                            name: '联盟广告',
                            type: 'line',
                            stack: '总量',
                            data: [220, 182, 191, 234, 290, 330, 310]
                        },
                        {
                            name: '搜索引擎',
                            type: 'line',
                            stack: '总量',
                            data: [820, 932, 901, 934, 1290, 1330, 1320]
                        }
                    ]
                });
            },
			drawBarChart() {
			    this.couponTypeChartBar = echarts.init(document.getElementById('couponTypeChartBar'));
			    this.couponTypeChartBar.setOption({
			        title: {
			            text: 'Bar Chart',
			            subtext: '数据来自网络'
			        },
			        tooltip: {
			            trigger: 'axis',
			            axisPointer: {
			                type: 'shadow'
			            }
			        },
			        legend: {
			            data: ['2011年', '2012年']
			        },
			        grid: {
			            left: '3%',
			            right: '4%',
			            bottom: '3%',
			            containLabel: true
			        },
			        xAxis: {
			            type: 'value',
			            boundaryGap: [0, 0.01]
			        },
			        yAxis: {
			            type: 'category',
			            data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
			        },
			        series: [
			            {
			                name: '2011年',
			                type: 'bar',
			                data: [18203, 23489, 29034, 104970, 131744, 630230]
			            },
			            {
			                name: '2012年',
			                type: 'bar',
			                data: [19325, 23438, 31000, 121594, 134141, 681807]
			            }
			        ]
			    });
			},
            drawPieChart() {
                this.publishCouponTypePie = echarts.init(document.getElementById('publishCouponTypePie'));
                this.publishCouponTypePie.setOption({
                    title: {
                        text: 'Pie Chart',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: [
                                { value: 335, name: '直接访问' },
                                { value: 310, name: '邮件营销' },
                                { value: 234, name: '联盟广告' },
                                { value: 135, name: '视频广告' },
                                { value: 1548, name: '搜索引擎' }
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
				this.usedCouponTypePie = echarts.init(document.getElementById('usedCouponTypePie'));
				this.usedCouponTypePie.setOption({
				    title: {
				        text: 'Pie Chart',
				        subtext: '纯属虚构',
				        x: 'center'
				    },
				    tooltip: {
				        trigger: 'item',
				        formatter: "{a} <br/>{b} : {c} ({d}%)"
				    },
				    legend: {
				        orient: 'vertical',
				        left: 'left',
				        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
				    },
				    series: [
				        {
				            name: '访问来源',
				            type: 'pie',
				            radius: '55%',
				            center: ['50%', '60%'],
				            data: [
				                { value: 335, name: '直接访问' },
				                { value: 310, name: '邮件营销' },
				                { value: 234, name: '联盟广告' },
				                { value: 135, name: '视频广告' },
				                { value: 1548, name: '搜索引擎' }
				            ],
				            itemStyle: {
				                emphasis: {
				                    shadowBlur: 10,
				                    shadowOffsetX: 0,
				                    shadowColor: 'rgba(0, 0, 0, 0.5)'
				                }
				            }
				        }
				    ]
				});
            }
        },

        updated: function () {
            this.drawCharts()
        }
    }
</script>

<style scoped>
    .chart-container {
        width: 100%;
        float: left;
    }
    /*.chart div {
        height: 400px;
        float: left;
    }*/

    .el-col {
        padding: 30px 20px;
    }
	
	.front-total-stat{
		font-size:24px
	}
	.front-total-stat-num{
		font-weight:bold;
		color:#F56C6C
	}
</style>
